package com.xyhuo.leetcode.january;

import com.xyhuo.leetcode.common.TreeNode;

/**
 * 相同的树
 * https://leetcode.cn/problems/same-tree/
 *
 * @time 2024/1/4
 */
public class IsSameTree {

    public boolean isSameTree(TreeNode p, TreeNode q) {
        search(p, q);
        return ans;
    }

    private boolean ans = true;

    private void search(TreeNode p, TreeNode q) {
        if (!ans) {
            return;
        }
        if (p == null && q == null) {
            return;
        } else if (p != null && q != null) {
            if (p.val != q.val) {
                ans = false;
                return;
            }
            search(p.left, q.left);
            search(p.right, q.right);
        } else {
            ans = false;
        }
    }

}
